package com.air.ota.service.imp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.air.common.util.QueryCondition;
import com.air.common.util.QueryExpression;
import com.air.ota.mo.InboundMsg;
import com.air.ota.mo.OutboundMsg;
import com.air.ota.service.ICardPwdService;
import com.air.ota.service.IModifyPwdHandlerService;
import com.air.ota.service.IOutboundMsgService;
import com.air.ota.service.ISMGPService;
import com.air.ota.util.HexStringUtil;
import com.air.ota.vo.UTKModifyPwdDownlinkVO;
import com.air.ota.vo.UTKModifyPwdUplinkVO;

@Service("modifyPwdHandlerService")
public class ModifyPwdHandlerServiceImp implements IModifyPwdHandlerService {
	
	@Autowired
	ICardPwdService cardPwdService;
	//@Autowired
	//IOutboundMsgService outboundMsgService;
	@Autowired
	ISMGPService smgpService;
	@Override
	public void process(UTKModifyPwdUplinkVO pkgVO, InboundMsg inboundMsg)
			throws Exception {
		
		
		
		//比对原始密码
		boolean authResult=cardPwdService.auth(inboundMsg.getPhoneNumber(), pkgVO.getOldPwdDecrypt());
		if (authResult){
			cardPwdService.setPwd(inboundMsg.getPhoneNumber(), pkgVO.getNewPwdDecrypt());
		}else{
			System.out.println("Old Passwood("+pkgVO.getOldPwdDecrypt()+") ERROR,Cant modify pwd");
		}
		byte result=0x01;
		if (authResult){
			System.out.println("MODIFY Passwood  SUCCESS NEW PWD=("+pkgVO.getNewPwdDecrypt());
			result=0x00;
			//send txt sms success
			
			smgpService.sendTxtSMS(inboundMsg.getPhoneNumber(), "服务密码修改成功！请牢记服务密码。");
		}else{
			//send txt sms failure
			smgpService.sendTxtSMS(inboundMsg.getPhoneNumber(), "服务密码修改失败！原服务密码错误，请重试。");
		}
		
		
		
		//回复下发短信
		/*UTKModifyPwdDownlinkVO modifyPwdDownlinkVO = new UTKModifyPwdDownlinkVO(pkgVO.getCardSequence(),
				pkgVO.getCardAppSequence(),result,null);
		byte[] responsePkg=modifyPwdDownlinkVO.buildPkg();
		*/
		
		
		//Insert outboundMsg List
		/*OutboundMsg outboundMsg = new OutboundMsg();
		outboundMsg.setContent(HexStringUtil.bytesToHexString(responsePkg));
		outboundMsg.setDest(0);
		outboundMsg.setPhoneNumber(inboundMsg.getPhoneNumber());
		outboundMsg.setSendDate(System.currentTimeMillis());
		outboundMsgService.insert(outboundMsg);*/
	}

}
